﻿//创建时间: 2010-12-19
//创建作者: 李城
//功能说明: CMS系统 日志管理 
//最后修改：李晓忠 2011.1.24
using System;
using System.Collections.Generic;
using System.Text;
using TRPOP.CMS.Plugin;
using System.Data;
using TRPOP.CMS.UserManage;
using TRPOP.Common;
namespace TRPOP.CMS.Log
{
    public class LogManage : ILog
    {

        public EnumSubmitResult SaveLog(int UserID, string UserName, string IP, string Action, string ActionURL, DateTime AddTime)
        {
            return (new LogDALSqlServer()).SaveLog(UserID, UserName, IP, Action, ActionURL, AddTime);
            //return EnumSubmitResult.Success;
        }

        public EnumSubmitResult SaveLog( string Action)
        {

            TRPOP.CMS.Plugin.IAdminUser m_IAdminUser = IAdminUserAccess.GetInstance();
            TRPOP.CMS.UserManage.AdminUserInfo mUserBaseInfo = m_IAdminUser.getUserBaseInfo() as TRPOP.CMS.UserManage.AdminUserInfo;
            if (mUserBaseInfo == null)
            {
                mUserBaseInfo = new AdminUserInfo();
                mUserBaseInfo.LogName = "未知";
                mUserBaseInfo.UserBaseId = 0;
            }
            return (new LogDALSqlServer()).SaveLog(mUserBaseInfo.UserBaseId, mUserBaseInfo.LogName, RequestHelper.GetIP(), Action, RequestHelper.GetCurrentUrl(), DateTime.Now);
            //return EnumSubmitResult.Success;
        }

        /// <summary>
        /// 删除 DeleteInfoById
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public EnumSubmitResult DeleteInfoById(int id)
        {
            return (new LogDALSqlServer()).DeleteInfoById(id);
            //return EnumSubmitResult.Success;
        }

        /// <summary>
        /// 删除 DeleteInfoByIds
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        public EnumSubmitResult DeleteInfoByIds(string ids)
        {
            //return EnumSubmitResult.Success;
             return (new LogDALSqlServer()).DeleteInfoByIds(ids);
        }

        /// <summary>
        /// 自定义列表（无分页） 
        /// </summary>
        /// <param name="topn"></param>
        /// <param name="condition"></param>
        /// <param name="orderby"></param>
        /// <returns></returns>
        public DataSet GetListByCondition(int topn, string condition, string orderby)
        {
            return (new LogDALSqlServer()).GetListByCondition(topn, condition, orderby);
        }

        /// <summary>
        /// 自定义列表（分页）
        /// </summary>
        /// <param name="pageNumber"></param>
        /// <param name="pageSize"></param>
        /// <param name="condition"></param>
        /// <param name="orderby"></param>
        /// <param name="recordCount"></param>
        /// <returns></returns>
        public DataSet GetListByPager(int pageNumber, int pageSize, string condition, string orderby, out int recordCount)
        {
            recordCount = 0;
            return (new LogDALSqlServer()).GetListByPager(pageNumber, pageSize, condition, orderby, out recordCount);
        }
        /// <summary>
        /// 操作日志
        /// </summary>
        /// <param name="oOperType"></param>
        /// <param name="oOperObject"></param>
        /// <param name="oObjArray"></param>
        public string OperLog(LogKeys.OperType oOperType, LogKeys.OperObject oOperObject, object[] oObjArray)
        {
            int intOperType = (int)oOperType;
            int intOperObject = (int)oOperObject;
            //新增 编辑 删除
            string strOperInfo = LogKeys.GetValueOperType(intOperType) + "_";//例如: 新增_ 
            //操作对象
            string strOperObject = "操作对象： " + LogKeys.GetValueOperObject(intOperObject);// 操作对象： 系统设置、结点管理
            //操作说明
            string strOperObjectInfo = LogKeys.GetValueOperObject(intOperObject);

            return string.Format(strOperObjectInfo, oObjArray);

        }

        /// <summary>
        /// 系统日志 根据异常 记录
        /// </summary>
        /// <param name="ex"></param>
        /// <param name="oObjArray"></param>
        /// <returns></returns>
        public string SysLog(Exception ex, object[] oObjArray)
        {
            return string.Format(LogKeys.GetValueSysLogTypeInfo((int)LogKeys.SysLogType.PageError), oObjArray);
        }
    }
}
